// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import router from './router'
import ElementUI from 'element-ui'
import VCharts from 'v-charts'
import 'element-ui/lib/theme-chalk/index.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

require("es6-promise").polyfill();
// import Avue from '@smallwei/avue';
// import '@smallwei/avue/lib/theme-chalk/index.css'

import App from './App'

Vue.config.productionTip = false

// Vue.use(Avue);
Vue.use(ElementUI);
Vue.use(VCharts)

// import Viser from 'viser-vue'
// Vue.use(Viser)

import Vue2OrgTree from 'vue2-org-tree';
Vue.use(Vue2OrgTree)

router.beforeEach((to, from, next) => {
    NProgress.start();
    if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
        if (localStorage.token) { // 判断当前的token是否存在
            next();
        }
        else {
            next({
                path: '/',
                query: {redirect: to.fullPath} // 将跳转的路由path作为参数，登录成功后跳转到该路由
            })
        }
    }
    else {
        next();
    }
});

router.afterEach(() => {
    NProgress.done() // finish progress bar
})
/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    components: {App},
    template: '<App/>'
})


